#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> arr(n);
	int _max = arr[0];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		_max = max(arr[i], _max);
	}
	vector<int> num(_max + 1);
	for (int i = 0; i < n; i++)
		num[arr[i]] += arr[i];
	vector<int> f(_max + 1), g(_max + 1);
	for (int i = 1; i <= _max; i++)
	{
		f[i] = max(g[i - 1] + num[i], f[i - 1]);
		g[i] = max(g[i - 1], f[i - 1]);
	}
	cout << (f[_max] > g[_max] ? f[_max] : g[_max]);
	return 0;
}